<?php
include "./inc/header.php";


title('数组');

comment('遍历数组, 访问数组元素');
$roles = array(
	array('name' => 'lufy', 'age' => 12),
	array('name' => 'nami', 'age' => 11)
);

foreach ($roles as $role) {
	// print() 不会自动换行?
	// print($role['name']);
	clog($role['name']);
}

foreach ($roles as $index => $role) {
	clog($index . ". " . $role['name'] . " {$role['age']}");
}


comment('创建数组后添加元素');
$nums = array();
$nums[] = 11;
$nums[] = 22;
$evens = array(22, 12, 10);
$colors = array('blue', 'red', 'pink');
print_r($nums);


title('数组方法', 3);
clogList(
	array(
		'array_sum()',
		'array_merge()',
		'array_diff()',
		'end()',
		'in_array()',
		'array_map()',
		'array_filter()',
		'array_reduce()',

	)
);

comment('数组元素求和');
clog(array_sum($nums));
comment('数组合并');
print_r(array_merge($nums, $colors));
comment('数组差集');
print_r(array_diff($nums, $evens));
comment('数组最后一个元素');
clog(end($nums));

comment('数组是否包含指定元素');
clog(in_array(11, $nums) ? 'yes' : 'no');

title('array_map方法');
$prices = [10, 20, 23];
clog(gettype($prices));
function mydouble($val)
{
	return $val * 2;
}
print_r(array_map('mydouble', $prices));


title('时间日期方法', 3);

clogList(
	array(
		'date()',
		'time()',
		'strtotime()',
	)
);

comment('获取当前时间');
var_dump(time());
newline();
var_dump(strtotime('-1 day'));
clog(date('Y-m-d H:i:s', time()));
clog('minute is: ' . date('i'));

include 'inc/footer.php';
